<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>注册页面</title>
			<link rel="stylesheet" href="css/layui/css/layui.css" media="all">
		<link rel="stylesheet"href="css/style.css">
		<script src="js/vue.js"></script>
		<script src="js/axios.min.js"></script>
		<script src="js/app.js" charset="UTF-8"></script>
		<script src="js/vue.js"></script>
		<script src="js/axios.min.js"></script>
		<script src="js/vue-cookies.js"></script>
		<script src="css/layui/layui.js" charset="utf-8"></script>
	
	</head>
	<body>


			<div id="particles-js"></div>
				<div id="app" class='loginregister'>
					<div>
						<h1 style="margin-bottom:20px;margin-left: 60px;font-family:Microsoft Yahei;">用户注册</h1>
					</div>
					<div>
						<label class="layui-form-label">用户名:</label>
							<div class="layui-input-block">
								<input v-model="username" placeholder="请输入用户名" class="layui-input">
							</div>
					</div>
		
					<div>
						<label class="layui-form-label">密码:</label>
							<div class="layui-input-block">
								<input v-model="password" placeholder="请输入密码" class="layui-input">
							</div>
					</div>	
		
					<div>
						<label class="layui-form-label">昵称:</label>
							<div class="layui-input-block">
								<input v-model="usershowname" placeholder="请输入昵称" class="layui-input">
							</div>
					</div>
					
				<div  class='loginregisterButton'>
					<div  style="width:400px;" >
						<button class="layui-btn layui-btn-fluid" @click="register" style="width:130px;margin-top: 20px;margin-left:30px;float:left;" >注册</button>
						<button class="layui-btn layui-btn-primary layui-btn-fluid" style="width:130px;margin-top: 20px;float:left;" @click="goLogin">回到登陆</button>
					</div>
					<div>管理员能看到密码</div>
					<div >试用请瞎写密码</div>
				</div>
				</div>
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		<script src="js/particles/particles.js"></script>
		<script src="js/particles/app.js"></script>

		<script type="text/javascript">
			var vm = new Vue({
				el: '#app',
				data: {
					username: '',
					password: '',
					usershowname: '',
				},
				methods: {
					goLogin:function(){
							window.location.href = 'login.html';
					},
					
					register: function() {
						if(this.username==''||this.password==''||this.usershowname=='')
						{
							layui.use('layer', function(){
							  var layer = layui.layer;
							layer.msg("用户名、密码、昵称不能为空")
							});
						}
						else{
						var postdata = JSON.stringify({
							userName: this.username,
							passWord: this.password,
							userShowName: this.username,

						});

						console.log(URL + '/user/register')
						console.log(postdata)
						axios.post(URL + '/user/register', postdata, {
								headers: {
									'Content-Type': 'application/json;charset=UTF-8'
								}
							})
							.then(function(response) {
								if (response.data.code == 1) {
									console.log(response)
									console.log(response.data.msg)
									layui.use('layer', function(){
									  var layer = layui.layer;
									 layer.confirm('注册成功，跳转到登陆页面', {title:'提示'}, function(index){
									 window.location.href="login.html"
									   layer.close(index);
									 });
									});    


								} else {
									console.log(response)
									console.log(response.data.msg)
									layui.use('layer', function(){
									  layer.msg("注册失败，可能重名")
									});    
								}
							})
							.catch(function(error) {
								console.log(error);
							});
					}

}
				}
			})
		</script>
	</body>
</html>
